package jsu.yym.tiktok.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import jsu.yym.tiktok.pojo.Like;
import jsu.yym.tiktok.pojo.User;
import jsu.yym.tiktok.pojo.Video;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;

import java.util.List;

@Mapper
public interface LikeMapper extends BaseMapper<Like> {

    //判断是否重复添加
    @Select("SELECT * FROM `like` WHERE username = #{username} and video_id = #{video_id}")
    Like getLikeByUsernameAndPkId(@Param("username") String username,@Param("video_id") int video_id);
    //获取用户点赞的数据
    @Select("SELECT video_id FROM `like` WHERE username = #{username}")
    List<Integer> getVideoIdsByUsernameAndState(@Param("username") String username);
    @Insert("INSERT INTO `like` (username, video_id) VALUES (#{username}, #{video_id})")
    void insertLike(Like like);

    @Delete("DELETE FROM `like` WHERE username = #{username} AND video_id = #{video_id}")
    void deleteLike(@Param("username") String username, @Param("video_id") int video_id);



}
